package io.ai.arch.java.rule.drools;

import lombok.extern.slf4j.Slf4j;
import org.drools.ruleunits.api.RuleUnitInstance;
import org.drools.ruleunits.api.RuleUnitProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

@Slf4j
public class DroolsApi {

    public static void main(String[] args) {
        MeasurementUnit measurementUnit = new MeasurementUnit();

        RuleUnitInstance<MeasurementUnit> instance = RuleUnitProvider.get().createRuleUnitInstance(measurementUnit);
        try {
            measurementUnit.getMeasurements().add(new Measurement("color", "red"));
            measurementUnit.getMeasurements().add(new Measurement("color", "green"));
            measurementUnit.getMeasurements().add(new Measurement("color", "blue"));

            List<Measurement> queryResult = instance.executeQuery("FindColor").toList("$m");
//            List<Measurement> queryResult = instance.executeQuery("FindColor").stream().map(tuple -> (Measurement) tuple.get("$m")).collect(toList());
            log.info("{}", queryResult.size());
            log.info("contains red: {}", measurementUnit.getControlSet().contains("red"));
            log.info("contains green: {}", measurementUnit.getControlSet().contains("green"));
            log.info("contains blue: {}", measurementUnit.getControlSet().contains("blue"));
        } finally {
            instance.close();
        }
    }
}
